package com.learner.course.repository;

import com.learner.pojo.course.CourseCollect;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;

/**
 * @Description: 课程收藏的接口
 * @Author: ice2020x
 * @Date: 2021/11/12
 */
@Repository
public interface CourseCollectRepository extends JpaRepository<CourseCollect, String> {

    /**
     * 判断该课程是否收藏
     *
     * @param courseId 课程id
     * @param memberId  userId
     * @return 结果
     */
    CourseCollect findByCourseIdAndMemberId(String courseId, String memberId);


    /**
     * 根据课程id和会员id取消收藏
     *
     * @param courseId 课程id
     * @param memberId 用户id
     * @return 结果
     */
    @Modifying
    @Transactional(rollbackOn = Exception.class)
    int deleteByCourseIdAndMemberId(String courseId, String memberId);
}
